﻿Public Class maspromotion
    Private PROID = Nothing
    Private PRONAME = Nothing
    Private REMARK = Nothing
    Private STDATE = Nothing
    Private ENDATE = Nothing
    Private STATUS = Nothing
    Private selectMaspromotion = "SELECT `proid` AS 'รหัสโปรโมชั่น', `proname` AS 'ชื่อโปรโมชั่น', `remark` AS 'คำอธิบาย', `stdate` AS 'วันที่เริ่มต้นโปรโมชั่น', `endate` AS 'วันที่สิ้นสุดโปรโมชั่น', `status` AS 'สถานะการเปิดใช้งาน' FROM maspromotion"
    'Private selectMasdrgacc = "SELECT DGTYID, DRGTYPE, convert(bit, [STATUS]) FROM MASDRGTYPE"

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection

    Property PROID_ As Integer
        Get
            Return PROID
        End Get
        Set(value As Integer)
            PROID = value
        End Set
    End Property

    Property PRONAME_ As String
        Get
            Return PRONAME
        End Get
        Set(value As String)
            PRONAME = value
        End Set
    End Property

    Property REMARK_ As String
        Get
            Return REMARK
        End Get
        Set(value As String)
            REMARK = value
        End Set
    End Property

    Property STDATE_ As String
        Get
            Return STDATE
        End Get
        Set(value As String)
            STDATE = value
        End Set
    End Property

    Property ENDATE_ As String
        Get
            Return ENDATE
        End Get
        Set(value As String)
            ENDATE = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectMaspromotion_ As String
        Get
            Return selectMaspromotion
        End Get
        Set(value As String)

        End Set
    End Property

    Public Sub insertMaspromotionData()
        If TypeOf PRONAME Is String Then
            If connect.GetTable("SELECT proid FROM maspromotion WHERE proname = '" & PRONAME & "'").Rows.Count > 0 Then
                MsgBox("มีข้อมูลโปรโมชั่นนี้อยู่ในระบบแล้ว")
            Else
                Try
                    connect = CONDB.NewConnection()
                    'connectlocal = conlocal.NewConnection()
                    'Dim dischargeID As Integer

                    connect.ExecuteNonQuery("INSERT INTO maspromotion (proname, remark, stdate, endate, status) VALUES ('" & PRONAME & "', '" & REMARK & "', '" & STDATE & "', '" & ENDATE & "', '" & STATUS & "')")
                    'dischargeID = connect.ExecuteScalar("INSERT INTO masdischarge (DISCHARGE, STATUS) VALUES ('" & masdischargeDescription & "', '" & masdischargeStatus & "'); SELECT LAST_INSERT_ID();")
                    'connectlocal.ExecuteNonQuery("INSERT INTO MASDISCHARGE (DISCHGID, DISCHARGE, STATUS) VALUES ('" & dischargeID & "', '" & masdischargeDescription & "', '" & masdischargeStatus & "')")
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลโปรโมชั่นเรียบร้อยแล้ว")
                Catch ex As Exception
                    MsgBox(vbCrLf & ex.Message)
                End Try
                connect.Dispose()
                'connectlocal.Dispose()
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub

    Public Sub editMaspromotionData()
        If TypeOf PRONAME Is String Then
            Try
                connect = CONDB.NewConnection()
                'connectlocal = conlocal.NewConnection()

                connect.ExecuteNonQuery("UPDATE maspromotion SET proname = '" & PRONAME & "', remark = '" & REMARK & "' , stdate = '" & STDATE & "' , endate = '" & ENDATE & "', status = '" & STATUS & "' WHERE proid = '" & PROID & "'")
                'connectlocal.ExecuteNonQuery("UPDATE MASDISCHARGE SET DISCHARGE = '" & masdischargeDescription & "', STATUS = '" & masdischargeStatus & "' WHERE DISCHGID = '" & masdischargeID & "'")
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลโปรโมชั่นเรียบร้อยแล้ว")
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
            End Try
            connect.Dispose()
            'connectlocal.Dispose()
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร")
        End If
    End Sub
End Class
